-
Notifications
You must be signed in to change notification settings - Fork 213
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add new simple examples for Sepolia testnet #89
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Thanks a lot |
odysseus0
approved these changes
Jul 19, 2024
Suggested edit: diff --git a/examples/simple_new.py b/examples/simple_new.py
index 7beb020..ed11117 100644
--- a/examples/simple_new.py
+++ b/examples/simple_new.py
@@ -2,26 +2,57 @@
Minimal viable example of flashbots usage with dynamic fee transactions.
Sends a bundle of two transactions which transfer some ETH into a random account.
+"eth_sendBundle" is a generic method that can be used to send a bundle to any relay.
+For instance, you can use the following relay URLs:
+ titan: 'https://rpc.titanbuilder.xyz/'
+ beaver: 'https://rpc.beaverbuild.org/'
+ builder69: 'https://builder0x69.io/'
+ rsync: 'https://rsync-builder.xyz/'
+ flashbots: 'https://relay.flashbots.net'
+
+You can simply replace the URL in the flashbot method to use a different relay like:
+ flashbot(w3, signer, YOUR_CHOSEN_RELAY_URL)
+
Environment Variables:
- ETH_SENDER_KEY: Private key of account which will send the ETH.
- ETH_SIGNER_KEY: Private key of account which will sign the bundle.
- This account is only used for reputation on flashbots and should be empty.
-- PROVIDER_URL: HTTP JSON-RPC Ethereum provider URL.
+- PROVIDER_URL: (Optional) HTTP JSON-RPC Ethereum provider URL. If not set, Flashbots Protect RPC will be used.
"""
import os
import secrets
from uuid import uuid4
+
from eth_account.account import Account
from eth_account.signers.local import LocalAccount
-from flashbots import flashbot
-from web3 import Web3, HTTPProvider
+from web3 import HTTPProvider, Web3
from web3.exceptions import TransactionNotFound
from web3.types import TxParams
-# change this to `False` if you want to use mainnet
-USE_SEPOLIA = True
-CHAIN_ID = 11155111 if USE_SEPOLIA else 1
+from flashbots import flashbot
+
+# Define the network to use
+NETWORK = "holesky" # Options: "sepolia", "holesky", "mainnet"
+
+# Define chain IDs and Flashbots Protect RPC URLs
+NETWORK_CONFIG = {
+ "sepolia": {
+ "chain_id": 11155111,
+ "provider_url": "https://rpc-sepolia.flashbots.net",
+ "relay_url": "https://relay-sepolia.flashbots.net",
+ },
+ "holesky": {
+ "chain_id": 17000,
+ "provider_url": "https://rpc-holesky.flashbots.net",
+ "relay_url": "https://relay-holesky.flashbots.net",
+ },
+ "mainnet": {
+ "chain_id": 1,
+ "provider_url": "https://rpc.flashbots.net",
+ "relay_url": None, # Mainnet uses default Flashbots relay
+ },
+}
def env(key: str) -> str:
@@ -42,22 +73,20 @@ def main() -> None:
# NOTE: this account should not store funds
signer: LocalAccount = Account.from_key(env("ETH_SIGNER_KEY"))
- w3 = Web3(HTTPProvider(env("PROVIDER_URL")))
-
- """
- "eth_sendBundle" is a generic method that can be used to send a bundle to any relay.
- For instance, you can use the following relay URLs:
- titan: 'https://rpc.titanbuilder.xyz/'
- beaver: 'https://rpc.beaverbuild.org/'
- builder69: 'https://builder0x69.io/'
- rsync: 'https://rsync-builder.xyz/'
- flashbots: 'https://relay.flashbots.net'
-
- You can simply replace the URL in the flashbot method to use a different relay like:
- flashbot(w3, signer, "https://rpc.titanbuilder.xyz/")
- """
- if USE_SEPOLIA:
- flashbot(w3, signer, "https://relay-sepolia.flashbots.net")
+ # Use user-provided RPC URL if available, otherwise use Flashbots Protect RPC
+ user_provider_url = env("PROVIDER_URL")
+ if user_provider_url:
+ provider_url = user_provider_url
+ print(f"Using user-provided RPC: {provider_url}")
+ else:
+ provider_url = NETWORK_CONFIG[NETWORK]["provider_url"]
+ print(f"Using Flashbots Protect RPC: {provider_url}")
+
+ w3 = Web3(HTTPProvider(provider_url))
+
+ relay_url = NETWORK_CONFIG[NETWORK]["relay_url"]
+ if relay_url:
+ flashbot(w3, signer, relay_url)
else:
flashbot(w3, signer)
@@ -82,7 +111,7 @@ def main() -> None:
"maxFeePerGas": Web3.toWei(200, "gwei"),
"maxPriorityFeePerGas": Web3.toWei(50, "gwei"),
"nonce": nonce,
- "chainId": CHAIN_ID,
+ "chainId": NETWORK_CONFIG[NETWORK]["chain_id"],
"type": 2,
}
tx1_signed = sender.sign_transaction(tx1)
@@ -94,7 +123,7 @@ def main() -> None:
"maxFeePerGas": Web3.toWei(200, "gwei"),
"maxPriorityFeePerGas": Web3.toWei(50, "gwei"),
"nonce": nonce + 1,
- "chainId": CHAIN_ID,
+ "chainId": NETWORK_CONFIG[NETWORK]["chain_id"],
"type": 2,
}
@@ -108,7 +137,7 @@ def main() -> None:
block = w3.eth.block_number
# Simulation is only supported on mainnet
- if not USE_SEPOLIA:
+ if NETWORK == "mainnet":
print(f"Simulating on block {block}")
# Simulate bundle on current block.
# If your RPC provider is not fast enough, you may get "block extrapolation negative"
|
- Add support for Sepolia, Holesky, and Mainnet networks - Introduce NETWORK_CONFIG for network-specific settings - Update provider and relay URL handling - Improve comments and documentation - Enhance error handling and logging
zeroXbrock
approved these changes
Jul 22, 2024
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice work, thank you!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Since Goerli gonna sunset, it makes sense to add new example based on Sepolia testnet.
Changes: